package util;

import java.util.Date;
import java.sql.Time;
import java.text.SimpleDateFormat;

import TouristManagement.DateV;
import TouristManagement.Hours;

public class Convert 
{
	//Convert java.util.Date to java.sql.Date
	public static java.sql.Date dateToDateSQL(Date in){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return java.sql.Date.valueOf(sdf.format(in));
	}
	
	//Convert java.util.Date to String
	public static String dateToString(Date in)
	{		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String dateStr = sdf.format(in);
		return dateStr;
	}
	
	//Convert ToutistManagement.DateV to java.util.Date
	public static DateV dateToDateV(java.util.Date in){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String str = sdf.format(in);
		short y = Short.valueOf(str.substring(0,4));
		short m = Short.valueOf(str.substring(5,7));
		short d = Short.valueOf(str.substring(8,10));
		DateV dv = new DateV(y,m,d);
		return dv;
	}
	
	//Convert java.sql.Time to ToutistManagement.Hours
	public static Hours timeToHours(java.sql.Time in){
		String str = in.toString();
		short h = Short.valueOf(str.substring(0,2));
		short m = Short.valueOf(str.substring(3,5));
		short s = Short.valueOf(str.substring(6,8));
		Hours dv = new Hours(h,m,s);
		return dv;
	}
	
//	public static void main(String[] args){
//		Time t= Time.valueOf("10:30:00");
//		Hours s= Convert.timeToHours(t);
//		System.out.println(s.hour+":"+s.minute+":"+s.seconde);
//		
//		
//		Date dateS = new Date();
//		
//		DateV dv =Convert.dateToDateV(dateS);
//		System.out.println(dv.year+"-"+dv.month+"-"+dv.day);
//		
//	}
	
}
